using Game.Main.Model;
using Game.XH;
using UnityEngine;

namespace Game.Component
{
	public class TrashcanItem : BaseItem
	{
		public enum Anim
		{
			Static = 0,
			Shake = 1
		}

		protected Anim anim;

		protected float animTimer;

		private Transform destoryPoint;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			destoryPoint = model.Find("DestroyPoint");
		}

		protected override void LateUpdate()
		{
			if (anim != 0 && anim == Anim.Shake)
			{
				animTimer += Time.deltaTime;
				if (animTimer <= 0.1f)
				{
					base.transform.SetLocalScaleXY(Mathf.Lerp(1f, 1.1f, animTimer * 10f), Mathf.Lerp(1f, 0.9f, animTimer * 10f));
					return;
				}
				if (animTimer <= 0.2f)
				{
					base.transform.SetLocalScaleXY(Mathf.Lerp(1.1f, 1f, (animTimer - 0.1f) * 10f), Mathf.Lerp(0.9f, 1f, (animTimer - 0.1f) * 10f));
					return;
				}
				base.transform.SetLocalScaleXY(1f, 1f);
				anim = Anim.Static;
			}
		}

		public override void PlayDestroyShakeAnim()
		{
			base.PlayDestroyShakeAnim();
			anim = Anim.Shake;
			animTimer = 0f;
		}

		public override bool CanDestroyItem(BaseItem item)
		{
			if (item.transform.position.y >= destoryPoint.position.y)
			{
				return true;
			}
			return false;
		}

		public override Transform GetDestroyPoint()
		{
			if (destoryPoint != null)
			{
				return destoryPoint;
			}
			return base.GetDestroyPoint();
		}
	}
}
